//
//  BaseCollectionViewController.m
//  Mike
//
//  Created by Mi on 15/11/9.
//  Copyright © 2015年 上海乐住信息技术有限公司. All rights reserved.
//

#import "BaseCollectionViewController.h"

@interface BaseCollectionViewController ()

@end

@implementation BaseCollectionViewController

#pragma mark - Life cycle

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(void)deallocRelease{
    [super deallocRelease];
    _dataSource = nil;
    _collectionView.delegate = nil;
    _collectionView.dataSource = nil;
    _collectionView = nil;
}

#pragma mark - Propertys

-(UIView *)blankHintView{
    if (!_blankHintView) {
        [self initBlankHintView];
    }
    return _blankHintView;
}

-(void)initBlankHintView{
    _blankHintView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
    _blankHintView.backgroundColor=XFUIColorFromRGB(0xf0f2f5);
//    UIImageView *imageView=[[UIImageView alloc]initWithFrame:CGRectMake(85,10,55,78)];
//    imageView.image = [UIImage imageNamed:@"nonetworkdefault"];
//    imageView.contentMode=UIViewContentModeScaleAspectFit;
//    UILabel *hintLabel=[[UILabel alloc]initWithFrame:CGRectMake( imageView.frame.origin.x+VIEW_W(imageView)+10, imageView.frame.origin.y+(VIEW_H(imageView)/2-10), 200, 40)];
//     UILabel *hintLabel=[[UILabel alloc]initWithFrame:CGRectMake( imageView.frame.origin.x+80+10, imageView.frame.origin.y+(40/2-10), 200, 40)];
    UILabel *hintLabel = [UILabel new];
    hintLabel.numberOfLines = 0;
    hintLabel.lineBreakMode = NSLineBreakByWordWrapping;
    hintLabel.textColor=[UIColor colorWithHexString:@"8a91a5"];
    hintLabel.backgroundColor = [UIColor clearColor];
    hintLabel.textAlignment=NSTextAlignmentLeft;
    hintLabel.font=[UIFont fontWithName:@"Helvetica Neue" size:15];
    hintLabel.text=_blankHintString;
    [_blankHintView addSubview:hintLabel];
    [hintLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(_blankHintView);
        make.centerY.equalTo(_blankHintView).offset(-80);
    }];
//    [_blankHintView addSubview:imageView];
}

#pragma mark - Data Source

-(void)loadDefaultDataSource{
    [super loadDefaultDataSource];
    _dataSource = [[NSMutableArray alloc] initWithCapacity:1];
}

#pragma mark - UICollectionView DataSource

-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
    if (_isMultiSection) {
        return _dataSource.count;
    }else{
        return 1;
    }
}

-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    if (_isMultiSection) {
        return [_dataSource[section] count];
    }else{
        return _dataSource.count;
    }
}

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    // in subClass
    return nil;
}

#pragma mark - UICollectionView Delegate

-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    [collectionView deselectItemAtIndexPath:indexPath animated:YES];
    _selectIndexPath=indexPath;
}

#pragma mark - Public Methods

-(void)initCollectionViewWithLayout:(UICollectionViewLayout *)collectionViewLayout{
    _collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:collectionViewLayout];
    _collectionView.delegate=self;
    _collectionView.dataSource=self;
}

- (void)reloadDataWithBlank{
    if (_isMultiSection) {
        BOOL isCountZero=YES;
        for (NSArray *array in self.dataSource) {
            if (array.count!=0) {
                isCountZero=NO;
                break;
            }
        }
        if (isCountZero) {
            [_collectionView addSubview:self.blankHintView];
        }else{
            [self.blankHintView removeFromSuperview];
        }
    }else{
        if (self.dataSource.count==0) {
            [_collectionView addSubview:self.blankHintView];
        }else{
            [self.blankHintView removeFromSuperview];
        }
    }
    [_collectionView reloadData];
}

@end
